<template>
  <div class="region">
    <div class="content">
      <div class="left">地区:</div>

      <ul>
        <li :class="{active:activeFlag==''}" @click="changeRegion('')">全部</li>
        <li v-for="item in RegionArr" :class="{active:activeFlag==item.value}" :key="item.value" @click="changeRegion(item.value)">{{ item.name }}</li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reqHospitalLevelAndRegion } from "@/api/home";
import { onMounted, ref } from "vue";
import type {
 
  HospitalLevelAndRegionResponseData,
  HospitalLevelAndRegionArr,
} from "@/api/home/type";
//地区组件挂载完毕获取地区数据
let RegionArr = ref<HospitalLevelAndRegionArr>([]);
let activeFlag = ref<string>('');
onMounted(() => {
  getRegion();
});
//存储全部地区的数据

const getRegion = async () => {
 // let result: HospitalLevelAndRegionResponseData =
 let result :any=
    (await reqHospitalLevelAndRegion("Beijin"));
    console.log(result.data);
  if (result.data.code == 200) {
    RegionArr.value = result.data.data;
  }
  
};
const changeRegion= (region:string)=>{
  activeFlag.value=region;
  $emit('getRegion',region);
}

let $emit = defineEmits(['getRegion']);
</script>

<style scoped lang="scss">
.region {
  color: #7f7f7f;
  margin-top: 10px;
  .content {
    display: flex;
    .left {
      margin-right: 10px;
      width: 50px;
    }
    ul {
      display: flex;
      flex-wrap: wrap;
      li {
        margin-right: 10px;
        margin-bottom: 10px;
        &.active {
          color: #55a6fe;
        }
      }
      li:hover {
        color: #55a6fe;
        cursor: pointer;
      }
    }
  }
}
</style>
